home *** CD-ROM | disk | FTP | other *** search
/ Floppyshop 2 / Floppyshop - 2.zip / Floppyshop - 2.iso / art&graf.ix / art-3485 / art-5570 / atsirds.lst < prev    next >
File List  |  1994-08-09  |  5KB  |  191 lines

  1. ' **** Atari SIRDS program v2.0 ****
  2. '    routine from the SIRDS FAQ
  3. '
  4. ' read *.red (raw) file into thedepth array
  5. ' write *.tga file out of thesird array
  6. '
  7. bkdepth%=-800             ! depth of background in pixels
  8. e%=180                    ! eye separation in pixels
  9. o%=700                    ! observer-screen distance in pixels
  10. oversam%=6                ! oversampling ratio -- can be 1, 2, 4, 6
  11. dohiddenrem!=FALSE        ! enable/disable SLOW hidden point removal
  12. xres%=640                 ! width of the picture in pixels
  13. yres%=470                 ! height of picture in pixels
  14. numcolors%=64
  15. '
  16. DIM thedepth|(xres%*yres%)
  17. depthofs%=VARPTR(thedepth|(0))
  18. DIM link%(xres%*oversam%)
  19. DIM pixels%(xres%*oversam%)
  20. DIM z%(xres%)
  21. DIM pal|(3*numcolors%)
  22. DIM thesird|(xres%*(yres%+10)*3)       ! add 10 "help lines"
  23. sirdofs%=VARPTR(thesird|(0))
  24. '
  25. FILESELECT "\*.red","",dep$
  26. IF dep$=""
  27.   END
  28. ENDIF
  29. PRINT "Input RAW depth file: ";dep$
  30. OPEN "i",#1,dep$
  31. BGET #1,depthofs%,xres%*yres%
  32. CLOSE #1
  33. '
  34. PRINT "Res. ";xres%;"x";yres%;", ";numcolors%;" colors, ";
  35. IF oversam%=1
  36.   PRINT "no oversampling";
  37. ELSE
  38.   PRINT oversam%;" times oversampling";
  39. ENDIF
  40. IF dohiddenrem!
  41.   PRINT ", hidden point removal."
  42. ELSE
  43.   PRINT "."
  44. ENDIF
  45. init_pal
  46. init_sirds
  47. do_sirds
  48. PRINT CHR$(7);
  49. '
  50. FILESELECT "\*.tga","",sir$
  51. IF sir$=""
  52.   END
  53. ENDIF
  54. PRINT "Output TGA SIRDS file: ";sir$
  55. OPEN "o",#1,sir$
  56. PRINT #1;CHR$(0);CHR$(0);CHR$(2);
  57. PRINT #1;CHR$(0);CHR$(0);CHR$(0);CHR$(0);CHR$(0);
  58. PRINT #1;CHR$(0);CHR$(0);CHR$(0);CHR$(0);
  59. PRINT #1;CHR$(xres% MOD 256);CHR$(xres% DIV 256);
  60. PRINT #1;CHR$((yres%+10) MOD 256);CHR$((yres%+10) DIV 256);
  61. PRINT #1;CHR$(24);CHR$(32);
  62. BPUT #1,sirdofs%,xres%*(yres%+10)*3
  63. CLOSE #1
  64. END
  65. '
  66. '
  67. '
  68. PROCEDURE init_pal
  69.   ' create palette with shades of gray
  70.   LOCAL n%,cscale
  71.   cscale=255/(numcolors%-1)
  72.   FOR n%=0 TO numcolors%-1
  73.     pal|(3*n%)=ROUND(n%*cscale)    ! blue
  74.     pal|(3*n%+1)=ROUND(n%*cscale)  ! green
  75.     pal|(3*n%+2)=ROUND(n%*cscale)  ! red
  76.   NEXT n%
  77. RETURN
  78. '
  79. PROCEDURE init_sirds
  80.   ' add "help lines"
  81.   LOCAL x%,y%,helpdist,th%
  82.   helpdist=ABS(bkdepth%)*e%/(2*(ABS(bkdepth%)+o%))
  83.   th%=0
  84.   FOR y%=9 DOWNTO 0
  85.     FOR x%=xres%/2-helpdist-th% TO xres%/2-helpdist+th%
  86.       thesird|(3*(y%*xres%+x%))=255        ! blue
  87.       thesird|(3*(y%*xres%+x%)+1)=255      ! green
  88.       thesird|(3*(y%*xres%+x%)+2)=255      ! red
  89.     NEXT x%
  90.     FOR x%=xres%/2+helpdist-th% TO xres%/2+helpdist+th%
  91.       thesird|(3*(y%*xres%+x%))=255
  92.       thesird|(3*(y%*xres%+x%)+1)=255
  93.       thesird|(3*(y%*xres%+x%)+2)=255
  94.     NEXT x%
  95.     INC th%
  96.   NEXT y%
  97. RETURN
  98. '
  99. PROCEDURE do_sirds
  100.   ' render the SIRDS
  101.   LOCAL x%,y%,h%,u%,dx%,c%,xx%,highest%,separation%,left%,right%,pp%,v,visible!
  102.   FOR y%=0 TO yres%-1
  103.     PRINT AT(1,3);"Rendering line ";y%+1;" of ";yres%
  104.     FOR x%=0 TO xres%*oversam%-1
  105.       link%(x%)=x%
  106.     NEXT x%
  107.     highest%=bkdepth%
  108.     FOR x%=0 TO xres%-1
  109.       ' h%=bkdepth%+128+63*(SIN(x%/70*PI)+COS(y%/70*PI))
  110.       h%=bkdepth%+thedepth|(y%*xres%+x%)
  111.       z%(x%)=h%
  112.       IF h%>highest%
  113.         highest%=h%
  114.       ENDIF
  115.     NEXT x%
  116.     FOR x%=0 TO xres%*oversam%-1
  117.       separation%=(e%*oversam%*z%(x%/oversam%))/(z%(x%/oversam%)-o%)
  118.       left%=x%-separation%/2
  119.       right%=left%+separation%
  120.       IF (left%>=0) AND (right%<xres%*oversam%)
  121.         visible!=TRUE
  122.         IF dohiddenrem!
  123.           v=2*(o%-z%(x%/oversam%))/e%
  124.           dx%=1
  125.           REPEAT
  126.             u%=z%(x%/oversam%)+dx%*v
  127.             IF (z%((x%+dx%)/oversam%)>=u%) OR (z%((x%-dx%)/oversam%)>=u%)
  128.               visible!=FALSE
  129.             ENDIF
  130.             INC dx%
  131.           UNTIL (u%>highest%) OR (NOT visible!)
  132.         ENDIF
  133.         IF visible!
  134.           link%(right%)=left%
  135.         ENDIF
  136.       ENDIF
  137.     NEXT x%
  138.     pp%=0
  139.     FOR x%=0 TO xres%*oversam%-1
  140.       IF link%(x%)=x%
  141.         IF (pp% MOD oversam%)=0
  142.           c%=RANDOM(numcolors%)
  143.         ENDIF
  144.         pixels%(x%)=c%
  145.         INC pp%
  146.       ELSE
  147.         pixels%(x%)=pixels%(link%(x%))
  148.       ENDIF
  149.     NEXT x%
  150.     FOR x%=0 TO xres%-1
  151.       xx%=x%*oversam%
  152.       SELECT oversam%
  153.       CASE 1
  154.         c%=pixels%(xx%)
  155.       CASE 2
  156.         IF (x%>0) AND (x%<xres%-1)
  157.           c%=pixels%(xx%)*42+(pixels%(xx%-1)+pixels%(xx%+1))*24
  158.           c%=c%+(pixels%(xx%-2)+pixels%(xx%+2))*5
  159.           c%=c%/100
  160.         ELSE
  161.           c%=pixels%(xx%)
  162.         ENDIF
  163.       CASE 4
  164.         IF (x%>0) AND (x%<xres%-1)
  165.           c%=pixels%(xx%)*26+(pixels%(xx%-1)+pixels%(xx%+1))*18
  166.           c%=c%+(pixels%(xx%-2)+pixels%(xx%+2))*12
  167.           c%=c%+(pixels%(xx%-3)+pixels%(xx%+3))*7
  168.           c%=c%/100
  169.         ELSE
  170.           c%=pixels%(xx%)
  171.         ENDIF
  172.       CASE 6
  173.         IF (x%>0) AND (x%<xres%-1)
  174.           c%=pixels%(xx%)*14+(pixels%(xx%-1)+pixels%(xx%+1))*14
  175.           c%=c%+(pixels%(xx%-2)+pixels%(xx%+2))*11
  176.           c%=c%+(pixels%(xx%-3)+pixels%(xx%+3))*8
  177.           c%=c%+(pixels%(xx%-4)+pixels%(xx%+4))*5
  178.           c%=c%+(pixels%(xx%-5)+pixels%(xx%+5))*3
  179.           c%=c%+(pixels%(xx%-6)+pixels%(xx%+6))*2
  180.           c%=c%/100
  181.         ELSE
  182.           c%=pixels%(xx%)
  183.         ENDIF
  184.       ENDSELECT
  185.       thesird|(3*((y%+10)*xres%+x%))=pal|(3*c%)      ! blue
  186.       thesird|(3*((y%+10)*xres%+x%)+1)=pal|(3*c%+1)  ! green
  187.       thesird|(3*((y%+10)*xres%+x%)+2)=pal|(3*c%+2)  ! red
  188.     NEXT x%
  189.   NEXT y%
  190. RETURN
  191.